package com.nx.cluster;

import com.nx.Constant;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

public class ClusterProducer {

    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("nx-user-cluster");
        producer.setNamesrvAddr(Constant.MQ);
        producer.setSendMsgTimeout(10*1000);
        producer.start();

        for (int i = 0; i < 4; i++){
            Message msg = new Message("nx-user-cluster",
                    "TagA",
                    "key" + i,
                    ("Hello world"+i).getBytes(RemotingHelper.DEFAULT_CHARSET));
            SendResult sendResult = producer.send(msg);
            System.out.printf("%s%n", sendResult);
        }

        producer.shutdown();
    }

}
